/** Lachlan Hewson-Doherty (h201384171)
 *  Diploma of Digital and Interactive Games
 *  lachlan_doherty@live.com.au
 *  2013
 */

package cabbage.model.logic;



import java.sql.SQLException;

import cabbage.controller.Cupcake;





public class CollectedGameplay {
	
	
	private Cupcake cc;
	
	
	
	
	
	
	
	
	
	
	public int insertCollected ( int livecollectible_id, int player_id ) throws SQLException{
		
		cc = new Cupcake();
		
		if (livecollectible_id == 0) return 0;
		if (player_id ==0) return 0;
		if (!checkLiveCollectibleidExists(livecollectible_id)) return 0;
		if (!checkPlayeridExists(player_id)) return 0;
		if (!checkForDuplicate(livecollectible_id, player_id)) return 0;
		
		return cc.insertCollected(livecollectible_id, player_id);
		
	}
	
	private boolean checkLiveCollectibleidExists ( int livecollectible_id ) throws SQLException{
		
		cc = new Cupcake();
		
		return cc.checkLiveCollectibleExists(livecollectible_id);
		
	}
	
	private boolean checkPlayeridExists ( int player_id ) throws SQLException{
		
		cc = new Cupcake();
		
		return cc.checkPlayerExists(player_id);
	}
	
	private boolean checkForDuplicate (int livecollectible_id, int player_id) throws SQLException {
		
		cc = new Cupcake();
		
		return cc.checkPlayerHasCollected(livecollectible_id, player_id);
	}

}
